<?php

class Invemercado_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }
    public function guardar(){
        if($this->input->post("inveMercadoId") == ""){
        $sql = "insert into inveMercados(inveMercadoInformante,inveMercadoUbicacion,inveMercadoCaractePredio,inveMercadoValorOferta,inveMercadoValorNegociar,inveMercadoAreaTerreno,inveMercadoAreaConstruccion,inveMercadoValMetroConstruccion,inveMercadoValorConstruccion,inveMercadoValorTerreno,inveMercadoValorMetroTerreno,visitaId,topografiasId) ";
        $sql .= "values('{$this->input->post("informante")}','{$this->input->post("ubicacion")}','{$this->input->post("caractPredio")}','{$this->input->post("valOferta")}','{$this->input->post("valNegocia")}','{$this->input->post("areTerrenoMetro")}','{$this->input->post("areaMetroConstru")}','{$this->input->post("valMetroContruccion")}','{$this->input->post("valorConstruccion")}','{$this->input->post("valorTerreno")}','{$this->input->post("valorMetroTerreno")}','{$this->input->post("visitaId")}','{$this->input->post("topografiaId")}')";
        }else{
            $sql = "update inveMercados set
                inveMercadoInformante = '{$this->input->post("informante")}',
                inveMercadoUbicacion = '{$this->input->post("ubicacion")}',
                inveMercadoCaractePredio = '{$this->input->post("caractPredio")}',
                inveMercadoValorOferta = '{$this->input->post("valOferta")}',
                inveMercadoValorNegociar = '{$this->input->post("valNegocia")}',
                inveMercadoAreaTerreno = '{$this->input->post("areTerrenoMetro")}',
                inveMercadoAreaConstruccion = '{$this->input->post("areaMetroConstru")}',
                inveMercadoValMetroConstruccion = '{$this->input->post("valMetroContruccion")}',
                inveMercadoValorConstruccion = '{$this->input->post("valorConstruccion")}',
                inveMercadoValorTerreno = '{$this->input->post("valorTerreno")}',
                inveMercadoValorMetroTerreno = '{$this->input->post("valorMetroTerreno")}',
                visitaId = '{$this->input->post("visitaId")}',
                topografiasId = '{$this->input->post("topografiaId")}'
                where inveMercadoId = {$this->input->post("inveMercadoId")}";
        }
        return $this->db->query($sql);
    } //fin public function guardar(){
    public function elimina($inveId){
        $sql = "delete from inveMercados where inveMercadoId = $inveId";
        return $this->db->query($sql);
    }
    public function obtieneDatos($inve){
        $sql = "select * from inveMercados mer
                inner join visitas vi on vi.visitaId = mer.visitaId 
                inner join avaluos ava on ava.avaluoId = vi.avaluoId
                inner join proyectos pro on pro.proyectoId = ava.proyectoId
                where mer.inveMercadoId = $inve";
        return $this->db->query($sql);
    }
} //fin class
?>
